package adapter;

import java.io.*;

public class Adapter {
    public static void main(String[] args) {
        System.out.println("adapter");
        // 文件流
        FileInputStream fileInputStream = null;
        // 转换器 一头链接 fileInputStream 一头链接 bufferedReader
        InputStreamReader inputStreamReader = null; // 适配器
        // 字符读出流
        BufferedReader bufferedReader = null;

        try {
            fileInputStream = new FileInputStream("/Users/yilianhudong/java_design_model_by_msb/doc/README.md");

//            bufferedReader = new BufferedReader(fileInputStream); // 此时fileInputStream字节流没有办法直接憝到字符流上这时候需要适配器

            // inputStreamReader 通过 inputStreamReader 将 fileInputStream 憝到 BufferedReader来
            inputStreamReader = new InputStreamReader(fileInputStream);
            // 读取转换之后的字节流
            bufferedReader = new BufferedReader(inputStreamReader);

            try {
                String line = bufferedReader.readLine();
                while (null != line){
                    System.out.println(line);
                    line = bufferedReader.readLine();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
                inputStreamReader.close();
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
